package com.ror.java.se.inet.tcp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Demo01TcpServer {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10000);
        Socket socket = ss.accept();
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        StringBuilder msg = new StringBuilder();
        int ch;
        while ((ch = br.read()) != -1) {
            msg.append((char) ch);
        }
        System.out.println(msg);
        OutputStream os = socket.getOutputStream();
        os.write("你好，TCP客户端！".getBytes());
        socket.shutdownOutput();
        socket.close();
        ss.close();
    }
}
